import heapq
class Solution(object):
    def lastStoneWeight(self, stones):
        """
        :type stones: List[int]
        :rtype: int
        """
        stones = [- stone for stone in stones]
        heapq.heapify(stones)
        while len(stones) > 1:
            node1 = - heapq.heappop(stones)
            node2 = - heapq.heappop(stones)
            if node1 != node2:
                heapq.heappush(stones, min(node1, node2) - max(node1, node2))
        if not stones:
            return 0
        else:
            return - stones.pop()
